﻿
using Microsoft.EntityFrameworkCore.Metadata;
using Models.Common;
using Models.Device;
using Models.TaskPlain;
using NetTaste;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Drawing2D;
using System.IO.Ports;
using System.Text;
using System.Threading;
using UtilsORM;
using UtilsORM.MySqlData;
using static Models.Common.EnumDeviceState;
using UtilsBase;
using GatewayServerService.CloudCenter;

namespace GatewayServerService.Device
{
    /// <summary>
    /// 普锐森社-风速变送器风
    /// </summary>
    public class ServiceDeviceRS4851025_FS
    {
        ServiceCloudDeviceValueLog log = new ServiceCloudDeviceValueLog();
        //回调获获状态,为了避免误差，查状态和执行，都返回了 当前开关状态
        public void callBackUpdate(MQReqModel<object> httpReqModel)
        {
            try
            {
                ModelReceverData modelDeviceData = httpReqModel.toServerData;
                CommandLogModel commandLogModel = httpReqModel.toGatewayData;
                string result = modelDeviceData.commandResults[0].value;
                double windSpeed = 0;
                if (commandLogModel.key == "windSpeed" && !string.IsNullOrWhiteSpace(result))
                {
                    //当前风速：0056H(十六进制)= 86=> 风速 = 8.6m/s
                    //01 03 02 00 56 38 7A
                    string dataHex1 = result.Substring(9, 5);
                    windSpeed = new UtilsDataTypeChange().hex16Convert10(dataHex1) * 0.1;
                    Console.WriteLine("----------------------------");
                    // Console.WriteLine(windSpeed.ToString());
                    //Console.WriteLine("风速："+UtilsNumber.GetNumberForLength(windSpeed, 1).ToString()+" m/s");
                    //Console.WriteLine(new UtilsDataTypeChange().hex16Convert10(dataHex1).ToString());
                    Console.WriteLine("----------------------------");

                    log.writeSensorlog(commandLogModel.d_guid, "windSpeed", UtilsNumber.GetNumberForLength(windSpeed, 1).ToString(), commandLogModel.name);
                }


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }

}
